home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / gufw / model / FrontEnd.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-11-02  |  7.7 KB  |  223 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import commands
  5. from Variable import Variable
  6.  
  7. class Frontend:
  8.     
  9.     def __init__(self):
  10.         self.variable = Variable()
  11.  
  12.     
  13.     def set_status(self, status):
  14.         commands.getstatusoutput(self.variable.get_command(status))
  15.         return status
  16.  
  17.     
  18.     def get_status(self):
  19.         status = commands.getstatusoutput(self.variable.get_command('status'))
  20.         if status[1].find('Status: active') != -1:
  21.             return self.variable.get_constant('enabled')
  22.         return self.variable.get_constant('disabled')
  23.  
  24.     
  25.     def set_default(self, default):
  26.         commands.getstatusoutput(self.variable.get_command(default))
  27.         return default
  28.  
  29.     
  30.     def get_default(self):
  31.         default = commands.getstatusoutput(self.variable.get_command('search_policy'))
  32.         if default[1].find('ACCEPT') != -1:
  33.             return self.variable.get_constant('allow')
  34.         if default[1].find('DROP') != -1:
  35.             return self.variable.get_constant('deny')
  36.         if default[1].find('REJECT') != -1:
  37.             return self.variable.get_constant('reject')
  38.  
  39.     
  40.     def get_rules(self):
  41.         rules = commands.getstatusoutput(self.variable.get_command('status'))
  42.         rule_lines = rules[1].split('\n')
  43.         return_rules = []
  44.         for descomponent_rules in rule_lines:
  45.             if descomponent_rules.find(self.variable.get_constant('allow_upper')) != -1 and descomponent_rules.find(self.variable.get_constant('deny_upper')) != -1 and descomponent_rules.find(self.variable.get_constant('limit_upper')) != -1 or descomponent_rules.find(self.variable.get_constant('reject_upper')) != -1:
  46.                 return_rules.append(descomponent_rules)
  47.                 continue
  48.         
  49.         return return_rules
  50.  
  51.     
  52.     def set_ufw_log(self, status_ufw_log):
  53.         commands.getstatusoutput(self.variable.get_command(status_ufw_log))
  54.         return status_ufw_log
  55.  
  56.     
  57.     def get_ufw_log(self):
  58.         status = commands.getstatusoutput(self.variable.get_command('status_verbose'))
  59.         if status[1].find('Logging: on (high)') != -1:
  60.             return self.variable.get_constant('ufw_log_high')
  61.         if status[1].find('Logging: on (medium)') != -1:
  62.             return self.variable.get_constant('ufw_log_medium')
  63.         if status[1].find('Logging: on (low)') != -1:
  64.             return self.variable.get_constant('ufw_log_low')
  65.         if status[1].find('Logging: on (full)') != -1:
  66.             return self.variable.get_constant('ufw_log_full')
  67.         return self.variable.get_constant('ufw_log_off')
  68.  
  69.     
  70.     def set_gufw_log(self, status_gufw_log):
  71.         if not self.variable.dev:
  72.             status_gufw_log_aux = status_gufw_log
  73.         else:
  74.             status_gufw_log_aux = status_gufw_log + '_dev'
  75.         commands.getstatusoutput(self.variable.get_command(status_gufw_log_aux))
  76.         return status_gufw_log
  77.  
  78.     
  79.     def get_gufw_log(self):
  80.         if not self.variable.dev:
  81.             command = commands.getstatusoutput(self.variable.get_command('cfg_gufw_log'))
  82.         else:
  83.             command = commands.getstatusoutput(self.variable.get_command('cfg_gufw_log_dev'))
  84.         if command[0] == 0:
  85.             return self.variable.get_constant('gufw_log_on')
  86.         return self.variable.get_constant('gufw_log_off')
  87.  
  88.     
  89.     def add_rule_component(self, service, action, protocol, fromip, fromport, toip, toport):
  90.         if service == self.variable.get_constant('service_no'):
  91.             rule = 'LANG=en ufw &action proto &protocol from &fromIP port &fromPort to &toIP port &toPort'
  92.         else:
  93.             rule = 'LANG=en ufw &action &toPort'
  94.         rule = rule.replace('&action', action)
  95.         if protocol != self.variable.get_constant('both'):
  96.             rule = rule.replace('&protocol', protocol)
  97.         else:
  98.             rule = rule.replace(' proto &protocol ', ' ')
  99.         if fromip != '':
  100.             rule = rule.replace('&fromIP', fromip)
  101.         else:
  102.             rule = rule.replace('&fromIP', self.variable.get_constant('any'))
  103.         if fromport != '':
  104.             rule = rule.replace('&fromPort', fromport)
  105.         else:
  106.             rule = rule.replace(' port &fromPort ', ' ')
  107.         if toip != '':
  108.             rule = rule.replace('&toIP', toip)
  109.         else:
  110.             rule = rule.replace('&toIP', self.variable.get_constant('any'))
  111.         if toport != '':
  112.             rule = rule.replace('&toPort', toport)
  113.         else:
  114.             rule = rule.replace(' port &toPort', '')
  115.         return rule
  116.  
  117.     
  118.     def add_rule(self, rule):
  119.         result = commands.getstatusoutput(rule)
  120.         return result[1]
  121.  
  122.     
  123.     def remove_rule_component(self, rule_to, action, rule_from):
  124.         protocol = ''
  125.         toip = ''
  126.         toport = ''
  127.         fromip = ''
  128.         fromport = ''
  129.         rule = 'LANG=en ufw delete &action proto &protocol from &fromIP port &fromPort to &toIP port &toPort'
  130.         if rule_to.find('/tcp') != -1 or rule_from.find('/tcp') != -1:
  131.             protocol = self.variable.get_constant('tcp')
  132.             rule_to = rule_to.replace('/tcp', '')
  133.             rule_from = rule_from.replace('/tcp', '')
  134.         elif rule_to.find('/udp') != -1 or rule_from.find('/udp') != -1:
  135.             protocol = self.variable.get_constant('udp')
  136.             rule_to = rule_to.replace('/udp', '')
  137.             rule_from = rule_from.replace('/udp', '')
  138.         else:
  139.             protocol = self.variable.get_constant('both')
  140.         to_aux = rule_to.split(' ')
  141.         if len(to_aux) == 1:
  142.             if to_aux[0] == self.variable.get_constant('anywhere'):
  143.                 toip = ''
  144.             elif to_aux[0].find('.') != -1 or len(to_aux[0]) > 11:
  145.                 toip = to_aux[0]
  146.             else:
  147.                 toport = to_aux[0]
  148.         elif len(to_aux) == 2:
  149.             toip = to_aux[0]
  150.             toport = to_aux[1]
  151.         elif len(to_aux) == 3:
  152.             rule = 'LANG=en ufw delete ' + to_aux[2]
  153.             return rule
  154.         from_aux = rule_from.split(' ')
  155.         if len(from_aux) == 1:
  156.             if from_aux[0] == self.variable.get_constant('anywhere'):
  157.                 fromip = ''
  158.             elif from_aux[0].find('.') != -1 or len(from_aux[0]) > 11:
  159.                 fromip = from_aux[0]
  160.             else:
  161.                 fromport = from_aux[0]
  162.         elif len(from_aux) == 2:
  163.             fromip = from_aux[0]
  164.             fromport = from_aux[1]
  165.         elif len(from_aux) == 3:
  166.             rule = 'LANG=en ufw delete ' + from_aux[2]
  167.             return rule
  168.         rule = rule.replace('&action', action)
  169.         if protocol != self.variable.get_constant('both'):
  170.             rule = rule.replace('&protocol', protocol)
  171.         else:
  172.             rule = rule.replace(' proto &protocol ', ' ')
  173.         if fromip != '':
  174.             rule = rule.replace('&fromIP', fromip)
  175.         else:
  176.             rule = rule.replace('&fromIP', self.variable.get_constant('any'))
  177.         if fromport != '':
  178.             rule = rule.replace('&fromPort', fromport)
  179.         else:
  180.             rule = rule.replace(' port &fromPort ', ' ')
  181.         if toip != '':
  182.             rule = rule.replace('&toIP', toip)
  183.         else:
  184.             rule = rule.replace('&toIP', self.variable.get_constant('any'))
  185.         if toport != '':
  186.             rule = rule.replace('&toPort', toport)
  187.         else:
  188.             rule = rule.replace(' port &toPort', '')
  189.         return rule
  190.  
  191.     
  192.     def remove_rule(self, rule):
  193.         result = commands.getstatusoutput(rule)
  194.         return result[1]
  195.  
  196.     
  197.     def get_old_size_window(self):
  198.         if not self.variable.dev:
  199.             command = self.variable.get_command('read_size_win')
  200.         else:
  201.             command = self.variable.get_command('read_size_win_dev')
  202.         width_height = commands.getstatusoutput(command)
  203.         if width_height[0] == 0:
  204.             width_height_split = width_height[1].split(';')
  205.             width = width_height_split[0].replace('width=', '')
  206.             height = width_height_split[1].replace('height=', '')
  207.         else:
  208.             width = self.variable.get_constant('window_width')
  209.             height = self.variable.get_constant('window_height')
  210.         return (int(width), int(height))
  211.  
  212.     
  213.     def save_size_window(self, win_width, win_height):
  214.         if not self.variable.dev:
  215.             command = self.variable.get_command('save_size_win')
  216.         else:
  217.             command = self.variable.get_command('save_size_win_dev')
  218.         command = command.replace('&1', str(win_width))
  219.         command = command.replace('&2', str(win_height))
  220.         commands.getstatusoutput(command)
  221.  
  222.  
  223.